package com.topscomm.gpm.xxljob;

import com.topscomm.basic.exception.MessageException;
import com.topscomm.cbo.pojo.CboDeptEntity;
import com.topscomm.cbo.pojo.CboOrgEntity;
import com.topscomm.cbo.pojo.CboUserEntity;
import com.topscomm.cbo.service.ICboDeptService;
import com.topscomm.cbo.service.ICboOrgService;
import com.topscomm.cbo.service.ICboUserService;
import com.topscomm.gpm.pojo.GpmProjectMilepostEntity;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.DateUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.gpm.GpmSystemConst;
import com.topscomm.gpm.pojo.GpmPMOStandardizationRecordEntity;
import com.topscomm.gpm.pojo.GpmProjectEntity;
import com.topscomm.gpm.pojo.GpmProjectSuperviseEntity;
import com.topscomm.gpm.service.impl.GpmPMOStandardizationRecordService;
import com.topscomm.gpm.service.impl.GpmProjectMilepostService;
import com.topscomm.gpm.service.impl.GpmProjectService;
import com.topscomm.gpm.service.impl.GpmProjectSuperviseService;
import com.topscomm.tap.common.FlowDatacodeCache;
import com.topscomm.tap.common.SessionUserBean;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@JobHandler(value = "projectAutomaticSuperviseJob")
@Component
public class ProjectAutomaticSuperviseJob extends IJobHandler {
    /**
     * @author zhangjunyao
     * @date 2021/12/21
     * @description:  项目超期/里程碑超期一天自动下发督办，只发一次，系统自动给项目经理/里程碑责任人下发督办单（期限3天）
     * @modify:
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ReturnT<String> execute(String param) throws Exception {
        try {
            GpmPMOStandardizationRecordService gpmPMOStandardizationRecordService = (GpmPMOStandardizationRecordService)
                    SpringUtil.getBean("gpmPMOStandardizationRecordService");
            GpmProjectService gpmProjectService = (GpmProjectService) SpringUtil.getBean("gpmProjectService");
            // 查询超期项目
            List<Map<String, Object>> overDueProjects = getOverdueProject();
            // 查询超期里程碑
            List<Map<String, Object>> overDueMilePosts = getOverdueMilePost();
            if (CollectionUtils.isEmpty(overDueProjects) && CollectionUtils.isEmpty(overDueMilePosts)) {
                return ReturnT.FAIL;
            }
            // 获取全部PMO各自管理的省区
            List<GpmPMOStandardizationRecordEntity> pmoEntities = gpmPMOStandardizationRecordService.listAll();
            // 获取全部PMO的个人信息
            List<CboUserEntity> userEntities = getPmoInfo(pmoEntities);
            // 获取全部PMO的部门信息
            List<CboDeptEntity> deptEntities = getPmoDeptInfo(userEntities);
            // 获取全部PMO的组织信息
            List<CboOrgEntity> orgEntities = getPmoOrgInfo(deptEntities);
            // 转化为map类型
            Map<String, CboUserEntity> userMap = userEntities.stream().collect(Collectors.toMap(
                    CboUserEntity::getCode, cboUserEntity -> cboUserEntity));
            Map<String, CboDeptEntity> deptMap = deptEntities.stream().collect(Collectors.toMap(
                    s -> ConvertUtil.convertToString(s.getId()), cboDeptEntity -> cboDeptEntity));
            Map<String, CboOrgEntity> orgMap = orgEntities.stream().collect(Collectors.toMap(
                    s -> ConvertUtil.convertToString(s.getId()), cboOrgEntity -> cboOrgEntity));
            // 日期加2天
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String format = simpleDateFormat.format(date);
            Date parse = simpleDateFormat.parse(format);
            Calendar instance = Calendar.getInstance();
            instance.setTime(parse);
            instance.add(Calendar.DAY_OF_YEAR, 3);
            Date time = instance.getTime();
            // 处理超期项目
            setSuperviseForProjects(overDueProjects, pmoEntities, userMap, deptMap, orgMap, time);
            // 处理超期里程碑
            setSuperviseForMilePost(overDueMilePosts, pmoEntities, userMap, deptMap, orgMap, time);
            return ReturnT.SUCCESS;
        } catch (Exception ex) {
            throw new MessageException(ex);
        }
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:查询超期项目
     * @return: List<Map<String, Object>>
     * @modify:
     */
    private List<Map<String, Object>> getOverdueProject() {
        GpmProjectService gpmProjectService = (GpmProjectService) SpringUtil.getBean("gpmProjectService");
        GpmProjectSuperviseService gpmProjectSuperviseService = (GpmProjectSuperviseService) SpringUtil.getBean("gpmProjectSuperviseService");
        StringBufferProxy sql = new StringBufferProxy();
        // 查询今天是超期第一天的项目
        sql.appendSingle(" TO_CHAR({0} + 1, 'yyyy-MM-dd') = TO_CHAR(SYSDATE, 'yyyy-MM-dd') AND {1} in ({2}) AND ENABLED = 1 ",
                GpmProjectEntity.FieldPlanenddate, GpmProjectEntity.FieldProjectstate, GpmSystemConst.ProjectOngoingState);
        List<Map<String, Object>> projectList = gpmProjectService.queryMapByWhere(sql.toString());
        if (projectList.isEmpty()) {
            return null;
        }
        sql.clear();
        List<Map<String, Object>> resultList = new ArrayList<>();
        String projectIds = projectList.stream().map(item -> ConvertUtil.convertToString(item.get("id")))
                .collect(Collectors.joining("','", "'", "'"));
        // 查询督办表是否存在超期项目的督办单
        sql.appendSingle("{0} in ({1}) and {2} = '1' and enabled = '1'", GpmProjectSuperviseEntity.FieldProjectid,
                projectIds, GpmProjectSuperviseEntity.FieldSuperviseobjecttype);
        List<Map<String, Object>> superviseEntities = gpmProjectSuperviseService.queryMapByWhere(sql.toString());
        // 若不存在督办单则把全部超期项目返回
        if (superviseEntities.isEmpty()) {
            return projectList;
        }
        // 若存在督办单，把没有督办单的超期项目返回
        Map<String, List<Map<String, Object>>> superviseMap = superviseEntities.stream().collect(
                Collectors.groupingBy(map -> ConvertUtil.convertToString(map.get("projectid")))
        );
        for (Map<String, Object> project : projectList) {
            String projectid = ConvertUtil.convertToString(project.get("id"));
            if (!superviseMap.containsKey(projectid)) {
                resultList.add(project);
            }
        }
        return resultList;
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:查询超期里程碑
     * @return: List<Map<String, Object>>
     * @modify:
     */
    private List<Map<String, Object>> getOverdueMilePost() {
        StringBufferProxy sql = new StringBufferProxy();
        GpmProjectMilepostService gpmProjectMilepostService = (GpmProjectMilepostService) SpringUtil.getBean("gpmProjectMilepostService");
        GpmProjectSuperviseService gpmProjectSuperviseService = (GpmProjectSuperviseService) SpringUtil.getBean("gpmProjectSuperviseService");
        // 查询今天是超期第一天的里程碑
        sql.appendSingle("TO_CHAR({0} + 1, 'yyyy-MM-dd') = TO_CHAR(SYSDATE, 'yyyy-MM-dd') AND {1} = '0' AND ENABLED = 1",
                GpmProjectMilepostEntity.FieldPlanfinishtime, GpmProjectMilepostEntity.FieldMilepoststate);
        List<Map<String, Object>> milePostList = gpmProjectMilepostService.queryMapByWhere(sql.toString());
        if (milePostList.isEmpty()) {
            return null;
        }
        sql.clear();
        List<Map<String, Object>> resultList = new ArrayList<>();
        String milepostCodes = milePostList.stream().map(item -> ConvertUtil.convertToString(item.get(GpmProjectMilepostEntity.FieldMilepostcode)))
                .collect(Collectors.joining("','", "'", "'"));
        // 查询督办表是否存在超期里程碑的督办单
        sql.appendSingle("{0} in ({1}) and {2} = '2' and enabled = '1'", GpmProjectSuperviseEntity.FieldSuperviseobjectcode,
                milepostCodes, GpmProjectSuperviseEntity.FieldSuperviseobjecttype);
        List<Map<String, Object>> superviseEntities = gpmProjectSuperviseService.queryMapByWhere(sql.toString());
        // 若不存在督办单则把全部超期里程碑返回
        if (superviseEntities.isEmpty()) {
            return milePostList;
        }
        // 若存在督办单，把没有督办单的超期里程碑返回
        Map<String, List<Map<String, Object>>> superviseMap = superviseEntities.stream().collect(
                Collectors.groupingBy(map -> ConvertUtil.convertToString(map.get(GpmProjectSuperviseEntity.FieldSuperviseobjectcode))));
        for (Map<String, Object> milepost : milePostList) {
            String milepostCode = ConvertUtil.convertToString(milepost.get(GpmProjectMilepostEntity.FieldMilepostcode));
            if (!superviseMap.containsKey(milepostCode)) {
                resultList.add(milepost);
            }
        }
        return resultList;
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:查询PMO人员信息
     * @return: List<CboUserEntity>
     * @modify:
     */
    private List<CboUserEntity> getPmoInfo(List<GpmPMOStandardizationRecordEntity> pmoEntities) {
        StringBufferProxy sql = new StringBufferProxy();
        ICboUserService cboUserService = (ICboUserService) SpringUtil.getBean("cboUserService");
        // 获取所有PMO的工号，查询全部PMO的人员信息
        String userCodes = pmoEntities.stream().map(item -> ConvertUtil.convertToString(item.getUsercode()))
                .collect(Collectors.joining("','", "'", "'"));
        sql.appendSingle("code in ({0})", userCodes);
        List<CboUserEntity> userEntities = cboUserService.queryByWhere(sql.toString());
        return userEntities;
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:查询PMO部门信息
     * @return: List<CboDeptEntity>
     * @modify:
     */
    private List<CboDeptEntity> getPmoDeptInfo(List<CboUserEntity> userEntities) {
        ICboDeptService cboDeptService = (ICboDeptService) SpringUtil.getBean("cboDeptService");
        // 根据人员信息查询全部PMO所属部门
        String workDeptIds = userEntities.stream().map(item -> ConvertUtil.convertToString(item.getWorkdeptid()))
                .collect(Collectors.joining("','", "'", "'"));
        List<CboDeptEntity> deptEntities = cboDeptService.queryByIds(workDeptIds);
        return deptEntities;
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:查询PMO组织信息
     * @return: List<CboOrgEntity>
     * @modify:
     */
    private List<CboOrgEntity> getPmoOrgInfo(List<CboDeptEntity> deptEntities) {
        ICboOrgService cboOrgService = (ICboOrgService) SpringUtil.getBean("cboOrgService");
        // 根据部门信息查询全部PMO所属组织
        String orgIds = deptEntities.stream().map(item -> ConvertUtil.convertToString(item.getOrgid()))
                .collect(Collectors.joining("','", "'", "'"));
        List<CboOrgEntity> orgEntities = cboOrgService.queryByIds(orgIds);
        return orgEntities;
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:封装超期项目督办单信息并提交审批
     * @return:
     * @modify:
     */
    private void setSuperviseForProjects(List<Map<String, Object>> overDueProjects,
                                         List<GpmPMOStandardizationRecordEntity> pmoEntities, Map<String, CboUserEntity> userMap,
                                         Map<String, CboDeptEntity> deptMap, Map<String, CboOrgEntity> orgMap, Date time) {
        if(CollectionUtils.isEmpty(overDueProjects)) {
            return;
        }
        GpmProjectSuperviseService gpmProjectSuperviseService = (GpmProjectSuperviseService) SpringUtil.getBean("gpmProjectSuperviseService");
        FlowDatacodeCache flowDatacodeCache = (FlowDatacodeCache) SpringUtil.getBean("flowDatacodeCache");
        // 给每个超期项目创建督办单并提交审批
        for (Map<String, Object> overDueProject : overDueProjects) {
            String deptCommonCode = ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldDeptcommoncode1));
            String userCode = "";
            // 查询超期项目归属的PMO工号
            for (GpmPMOStandardizationRecordEntity pmoEntity : pmoEntities) {
                String chargeProvinces = pmoEntity.getChargeprovinces();
                if (chargeProvinces.contains(deptCommonCode)) {
                    userCode = pmoEntity.getUsercode();
                    break;
                }
            }
            // 获取该超期项目对应的PMO信息
            CboUserEntity userEntity = userMap.get(userCode);
            CboDeptEntity deptEntity = deptMap.get(ConvertUtil.convertToString(userEntity.getWorkdeptid()));
            CboOrgEntity orgEntity = orgMap.get(ConvertUtil.convertToString(deptEntity.getOrgid()));
            List<Map<String, Object>> flowIdList = flowDatacodeCache.getApprovalFlowListMap(
                    "ApprovalFlow_GpmProjectSupervise", userCode, "sortcode");
            // 添加督办单信息
            GpmProjectSuperviseEntity superviseEntity = new GpmProjectSuperviseEntity();
            superviseEntity.setSupervisename(overDueProject.get("projectname") + "督办单");
            superviseEntity.setFlowid(ConvertUtil.convertToLong(flowIdList.get(0).get("id")));
            superviseEntity.setSuperviseobjecttype("1");
            superviseEntity.setProjectid(ConvertUtil.convertToLong(overDueProject.get("id")));
            superviseEntity.setProjectcode(ConvertUtil.convertToString(overDueProject.get("projectcode")));
            superviseEntity.setProjectname(ConvertUtil.convertToString(overDueProject.get("projectname")));
            superviseEntity.setSuperviseobject(ConvertUtil.convertToString(overDueProject.get("projectname")));
            superviseEntity.setSuperviseobjectcode(ConvertUtil.convertToString(overDueProject.get("projectcode")));
            superviseEntity.setResponsiblename(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldProjectmanager)));
            superviseEntity.setResponsiblecode(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldProjectmanagercode)));
            superviseEntity.setSuperviseperiod(time);
            superviseEntity.setSupervisereason("该项目已超期");
            superviseEntity.setSupervisedeptname(deptEntity.getFullname());
            superviseEntity.setSupervisedeptcode(deptEntity.getCode());
            superviseEntity.setSupervisepeople(userEntity.getName());
            superviseEntity.setSupervisepeoplecode(userEntity.getCode());
            superviseEntity.setSupervisestate("0");
            superviseEntity.setDeptcommoncode1(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldDeptcommoncode1)));
            superviseEntity.setDeptname(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldDeptname)));
            superviseEntity.setDeptcode(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldDeptcode)));
            superviseEntity.setApplydeptname(deptEntity.getName());
            superviseEntity.setApplydeptcode(deptEntity.getCode());
            superviseEntity.setApplyorgcode(orgEntity.getCode());
            superviseEntity.setApplyorgname(orgEntity.getName());
            superviseEntity.setOrgname(orgEntity.getName());
            superviseEntity.setOrgcode(orgEntity.getCode());
            superviseEntity.setUsername(userEntity.getName());
            superviseEntity.setUsercode(userEntity.getCode());
            superviseEntity.setApplyusercode(userEntity.getCode());
            superviseEntity.setApplyusername(userEntity.getName());
            superviseEntity.setProjectmanager(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldProjectmanager)));
            superviseEntity.setProjectmanagercode(ConvertUtil.convertToString(overDueProject.get(GpmProjectEntity.FieldProjectmanagercode)));
            superviseEntity.setDocdate(new Date());
            superviseEntity.setSubmitdate(new Date());
            superviseEntity.setSendresource(1);
            // 督办表提交审批
            StringBufferProxy mainTitle = new StringBufferProxy();
            mainTitle.appendSingle("{0}{1}于{2}提交项目督办申请! ", deptEntity.getName(),
                    userEntity.getName(), DateUtil.dateToString(new Date(), "yyyy-MM-dd"));
            SessionUserBean sessionUserBean = new SessionUserBean();
            sessionUserBean.setUser(userEntity);
            sessionUserBean.setDept(deptEntity);
            sessionUserBean.setWorkDept(deptEntity);
            sessionUserBean.setOrg(orgEntity);
            sessionUserBean.setWorkOrg(orgEntity);
            //提交督办单据
            gpmProjectSuperviseService.executeSubmit(superviseEntity, mainTitle.toString(), sessionUserBean);
        }
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:封装超期里程碑督办单信息并提交审批
     * @return:
     * @modify:
     */
    private void setSuperviseForMilePost(List<Map<String, Object>> overDueMilePosts,
                                         List<GpmPMOStandardizationRecordEntity> pmoEntities, Map<String, CboUserEntity> userMap,
                                         Map<String, CboDeptEntity> deptMap, Map<String, CboOrgEntity> orgMap, Date time) {
        if (CollectionUtils.isEmpty(overDueMilePosts)) {
            return;
        }
        GpmProjectSuperviseService gpmProjectSuperviseService = (GpmProjectSuperviseService) SpringUtil.getBean("gpmProjectSuperviseService");
        FlowDatacodeCache flowDatacodeCache = (FlowDatacodeCache) SpringUtil.getBean("flowDatacodeCache");
        // 获取超期里程碑对应的项目，并转为map类型
        Map<String, GpmProjectEntity> projectMap = getProjectByMilePost(overDueMilePosts);
        // 给每个超期里程碑创建督办单
        for (Map<String, Object> overDueMilePost : overDueMilePosts) {
            String projectId = ConvertUtil.convertToString(overDueMilePost.get("projectid"));
            GpmProjectEntity projectEntity = projectMap.get(projectId);
            String pmoDeptCommonCode = ConvertUtil.convertToString(projectEntity.getDeptcommoncode1());
            String userCode = "";
            // 查询超期项目归属的PMO工号
            for (GpmPMOStandardizationRecordEntity pmoEntity : pmoEntities) {
                String chargeProvinces = pmoEntity.getChargeprovinces();
                if (chargeProvinces.contains(pmoDeptCommonCode)) {
                    userCode = pmoEntity.getUsercode();
                    break;
                }
            }
            // 获取该超期项目对应的PMO信息
            CboUserEntity userEntity = userMap.get(userCode);
            CboDeptEntity deptEntity = deptMap.get(ConvertUtil.convertToString(userEntity.getWorkdeptid()));
            CboOrgEntity orgEntity = orgMap.get(ConvertUtil.convertToString(deptEntity.getOrgid()));
            List<Map<String, Object>> flowIdList = flowDatacodeCache.getApprovalFlowListMap(
                    "ApprovalFlow_GpmProjectSupervise", userCode, "sortcode");
            // 添加督办单
            GpmProjectSuperviseEntity superviseEntity = new GpmProjectSuperviseEntity();
            superviseEntity.setSupervisename(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectMilepostEntity.FieldMilepostname))+"督办单");
            superviseEntity.setFlowid(ConvertUtil.convertToLong(flowIdList.get(0).get("id")));
            superviseEntity.setSuperviseobjecttype("2");
            superviseEntity.setProjectid(projectEntity.getId());
            superviseEntity.setProjectcode(projectEntity.getProjectcode());
            superviseEntity.setProjectname(projectEntity.getProjectname());
            superviseEntity.setSuperviseobject(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectMilepostEntity.FieldMilepostname)));
            superviseEntity.setSuperviseobjectcode(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectMilepostEntity.FieldMilepostcode)));
            superviseEntity.setResponsiblename(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectMilepostEntity.FieldResponsible)));
            superviseEntity.setResponsiblecode(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectMilepostEntity.FieldResponsiblecode)));
            superviseEntity.setSuperviseperiod(time);
            superviseEntity.setSupervisereason("该里程碑已超期");
            superviseEntity.setSupervisedeptname(deptEntity.getName());
            superviseEntity.setSupervisedeptcode(deptEntity.getCode());
            superviseEntity.setSupervisepeople(userEntity.getName());
            superviseEntity.setSupervisepeoplecode(userEntity.getCode());
            superviseEntity.setSupervisestate("0");
            superviseEntity.setDeptname(projectEntity.getDeptname());
            superviseEntity.setDeptcode(projectEntity.getDeptcode());
            superviseEntity.setApplydeptname(deptEntity.getName());
            superviseEntity.setApplydeptcode(deptEntity.getCode());
            superviseEntity.setApplyorgcode(orgEntity.getCode());
            superviseEntity.setApplyorgname(orgEntity.getName());
            superviseEntity.setOrgname(orgEntity.getName());
            superviseEntity.setOrgcode(orgEntity.getCode());
            superviseEntity.setUsername(userEntity.getName());
            superviseEntity.setUsercode(userEntity.getCode());
            superviseEntity.setApplyusercode(userEntity.getCode());
            superviseEntity.setApplyusername(userEntity.getName());
            superviseEntity.setProjectmanager(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectEntity.FieldProjectmanager)));
            superviseEntity.setProjectmanagercode(ConvertUtil.convertToString(overDueMilePost.get(GpmProjectEntity.FieldProjectmanagercode)));
            superviseEntity.setDocdate(new Date());
            superviseEntity.setSubmitdate(new Date());
            superviseEntity.setSendresource(1);
            // 督办单提交审批
            StringBufferProxy mainTitle = new StringBufferProxy();
            mainTitle.appendSingle("{0}{1}于{2}提交项目督办申请! ",deptEntity.getName(),
                    userEntity.getName(), DateUtil.dateToString(new Date(), "yyyy-MM-dd"));
            SessionUserBean sessionUserBean = new SessionUserBean();
            sessionUserBean.setUser(userEntity);
            sessionUserBean.setDept(deptEntity);
            sessionUserBean.setWorkDept(deptEntity);
            sessionUserBean.setOrg(orgEntity);
            sessionUserBean.setWorkOrg(orgEntity);
            //提交督办单据
            gpmProjectSuperviseService.executeSubmit(superviseEntity,mainTitle.toString(),sessionUserBean);
        }
    }

    /**
     * @author: zhangjunyao
     * @date: 2021-12-21
     * @description:根据超期里程碑查询对应项目
     * @return: Map<String, MpmProjectEntity>
     * @modify:
     */
    private Map<String, GpmProjectEntity> getProjectByMilePost(List<Map<String, Object>> overDueMilePosts) {
        GpmProjectService gpmProjectService = (GpmProjectService) SpringUtil.getBean("gpmProjectService");
        StringBufferProxy sql = new StringBufferProxy();
        String projectIds = overDueMilePosts.stream().map(item -> ConvertUtil.convertToString(item.get("projectid")))
                .collect(Collectors.joining("','", "'", "'"));
        List<GpmProjectEntity> projectEntities = gpmProjectService.queryByIds(projectIds);
        // 转为map类型
        Map<String, GpmProjectEntity> projectMap = projectEntities.stream().collect(Collectors.toMap(
                entity -> ConvertUtil.convertToString(entity.getId()), sdProjectEntity -> sdProjectEntity));
        return projectMap;
    }
}
